package com.cloudlead.common.worker.action.impl;

import java.util.Map;

import com.cloudlead.common.lang.api.ActionRequest;
import com.cloudlead.common.lang.api.RequestHeaderContext;
import com.cloudlead.common.lang.api.SimpleActionRequest;
import com.cloudlead.common.lang.api.SimpleActionResponse;

public abstract class AbstractSimpleAction extends
        AbstractAction<SimpleActionRequest, SimpleActionResponse<Object>> {

    @Override
    public SimpleActionResponse<Object> execute(SimpleActionRequest request) throws Exception{
        Map<String, String> requestHeaders = request.getRequestHeaders();
        requestHeaders.put(ActionRequest.REQUEST_ID, request.getRequestId());
        requestHeaders.put(ActionRequest.ACCESS_TOKEN, request.getAccessToken());
        RequestHeaderContext.setRequestHeaders(requestHeaders);
        return new SimpleActionResponse<>(process(request.getContent()));
    }

    public abstract Object process(Map<String, Object> request) throws Exception;

}
